// index.js
// 获取应用实例
Page({
  data: {
    current: 0,
    autoplay: true,
    duration: 500,
    interval: 3000,
    pageData: {},
    swiperList: [],
    visible: true,
    marquee: {
      speed: 60,
      loop: -1,
      delay: 0,
    },
    navBar: []
  },
  onLoad() {
    this.getIndexDetail()
  },
  // 获取首页信息
  async getIndexDetail() {
    const res = await wx.http.get('/page/detail')
    const pageData = res.data.data.pageData

    // 将轮播图URL存入data
    const bannerList = pageData.items[1].data
    const swiperList = bannerList.map(item => item.imgUrl)

    // 将导航栏信息存入data
    const navBar = pageData.items[3].data
    this.setData({pageData, swiperList, navBar})
  },
  // 点击跳转搜索页
  toSearch() {
    wx.navigateTo({
      url: '../search/search',
    })
  },
  // 点击跳转商品详情
  toDetail(ev) {
    wx.redirectTo({
      url: `../gooddetail/gooddetail?goods_id=${ev.mark.goods_id}`
    })
  }
})
